<!DOCTYPE html>
<html >
<head>
    <meta charset="UTF-8">
    <title>实名认证</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">

    <link rel="stylesheet" href="/sunfc/css/weui.min.css">
    <link rel="stylesheet" href="/sunfc/css/style.css">
    <style>

        .weui-cell:before {

            border-top: 0px solid #e5e5e5;

        }
        .weui-cells {
            margin-top:10px;

        }
        .weui-cells:before {

            border-top: 15px solid #f4f4f4;

        }
        .weui-cells:after {
            border-bottom: 0px solid #e5e5e5;
        }
        ::-webkit-input-placeholder{
            font-size: 15px;
            color: #CECECE;
        }

    </style>
</head>
<body  >
<div class="index-top">

    <div class="index-back">
        <a href="{:url('index/sunfc.users/index')}">
        <img src="/sunfc/images/back.png" width="15">
        </a>
    </div>

    <p class="index-title">实名认证</p>
</div>

<!-- 这里写内容 -->
<div   style="">
    <div class="weui-panel__bd"  style="margin-top:40px;background:white">
        <a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg">
            <div class="weui-media-box__hd" style="width:25%">
                <img class="weui-media-box__thumb"   style="width:100%;height:100px" src="/sunfc/images/sfz1.png">
            </div>
            <div class="weui-media-box__bd">
                <h4 class="weui-media-box__title">身份认证</h4>
                <p class="weui-media-box__desc"   style="margin-top:5px;">仅支持中国居民身份证进行实名认证</p>
            </div>
        </a>
    </div>

<!--<form action="{:url('liu.users/auth_user')}" method="post">-->
    <div class="weui-cells">
        <div class="weui-cells__title"  style="color: #737373;margin-top: 20px" >手机号码</div>
        <div class="weui-cell">
            <div class="weui-cell__bd">


                {if condition="($res.auth_user == 2) OR ($res.auth_user == 1)"}
                <input style="width:97%;border:1px  solid  #f4f4f4;height:40px;border-radius: 5px;padding-left: 3%" class="weui-input" type="text" placeholder="请填写手机号码" value="{$res.tel}">
                {else /}
                <input id="phone" style="width:65%;border:1px  solid rgb(239,239,244) ;height:40px;border-radius: 5px;padding-left: 3%"   class="weui-input" type="text" placeholder="请填写手机号码">
                <input type="button" id="btn" value="获取验证码" onclick="myFunction()" style="display:inline-block;width:28%;float:right;text-align:center;font-size: 13px;height:40px;line-height:40px;border-radius:5px;background:#4B4C5E;color:#fff;" />
                {/if}
            </div>
        </div>
        {if condition="($res.auth_user == 2) OR ($res.auth_user == 1)"}
        {else /}
        <div class="weui-cells__title"  style="color: #737373"  >验证码</div>
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <input id="password" style="width:97%;border:1px  solid  #f4f4f4;height:40px;border-radius: 5px;padding-left: 3%"   class="weui-input" type="text" placeholder="请填写手机验证码">
            </div>
        </div>
        {/if}
        <div class="weui-cells__title"  style="color: #737373;margin-top: 20px" >真实姓名</div>
        <div class="weui-cell">
            <div class="weui-cell__bd">
                {if condition="($res.auth_user == 2) OR ($res.auth_user == 1)"}
                <input  style="width:100%;border:1px  solid rgb(239,239,244) ;height:40px;border-radius: 5px;padding-left: 10px"   class="weui-input" type="text" placeholder="请填写身份证姓名"  value="{$res.realname}">
                {else /}
                <input id="realname" style="width:100%;border:1px  solid rgb(239,239,244) ;height:40px;border-radius: 5px;padding-left: 10px"   class="weui-input" type="text" placeholder="请填写身份证姓名"  value="">
                {/if}

            </div>
        </div>
        <div class="weui-cells__title"  style="color: #737373"  >身份证号</div>
        <div class="weui-cell">
            <div class="weui-cell__bd">
                {if condition="($res.auth_user == 2) OR ($res.auth_user == 1)"}
                <input style="width:100%;border:1px  solid  #f4f4f4;height:40px;border-radius: 5px;padding-left: 10px"   class="weui-input" type="text" placeholder="请填写18位身份证号"  value="{$res.id_card}">
                {else /}
                <input id="idcard" style="width:100%;border:1px  solid  #f4f4f4;height:40px;border-radius: 5px;padding-left: 10px"   class="weui-input" type="text" placeholder="请填写18位身份证号"  value="">
                {/if}
            </div>
        </div>
        {if condition="($res.auth_user == 2) OR ($res.auth_user == 1)"}
        {else /}
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <input type="hidden" id="uid" value="{$uid}">
                <input  style="width:100%;height:45px;border-radius: 5px;background:#CCCCCC;color:white;" id="bt1"   class="weui-input" type="hidden" value="提交审核">

                <!--提交后点亮的按钮-->
                <input  style="width:100%;height:45px;border-radius: 5px;background:#4B4C5E;color:white;" id="bt2"  class="weui-input" type="submit" value="提交审核">
            </div>
        </div>
        {/if}


    </div>
<!--</form>-->
    <div class="pt40">
    </div>
</div>
<script src="/sunfc/js/jquery.js"></script>

<script>
    $(document).ready(function(){
        $("#bt2").click(function(){
            if(!$('#idcard').val()){
                return false;
            }
            var idcard    = $('#idcard').val();
            //alert(idcard);
            $.post("{:url('sunfc.users/checkIdCard')}",
                {
                    id_card:idcard,
                },
                function(data){
                    if(data.code==1){
                            // 身份证号码正确
                            //alert(data.msg);
                            var real_name   = $('#realname').val();
                            var idcard      = $('#idcard').val();
                            var u_id        = $("#uid").val();
                            var iphone         = $("#phone").val();
                            var pass_word         = $("#password").val();
                            $.post("{:url('sunfc.users/authuser')}",
                                {
                                    realname:real_name,
                                    id_card:idcard,
                                    uid:u_id,
                                    tel:iphone,
                                    password:pass_word
                                },
                                function(data){
                                    if(data.code==1){
                                        alert(data.msg);
                                        window.location.href="{:url('index/sunfc.users/index')}";
                                    }else {
                                        alert('信息提交失败');
                                    }
                                });

                    }else {
                        // 身份证号码有误
                        alert(data.msg);
                    }
                });

        });
    });
</script>
<script type="text/javascript">
    var countdown=30;
    function settime(obj) {
        var x=document.getElementById('btn');
        if (countdown == 0) {
            x.removeAttribute("disabled");
            x.value="获取验证码";
            countdown = 30;
            document.getElementById('phone').removeAttribute("disabled");
            return;
        } else {
            x.setAttribute("disabled", true);
            x.value="重新发送(" + countdown + ")";
            countdown--;

        }
        setTimeout(function() {
                settime(obj) }
            ,1000);

    }


    function myFunction() {
        var tel = $('#phone').val()
        if(!tel){
            // 手机号码未填写
            return false;
        }else{
            // 手机号码填写不为空
            // 判断手机号码是否注册过
            $.post("{:url('sunfc.users/checkphone')}",{phone : tel},function (res) {
                if(res.code==1){
                    // 手机号码未注册
                    // 锁定输入框
                    document.getElementById('phone').setAttribute("disabled", true);


                    // 判断手机号格式与发送验证码状态
                    $.post('/home/auth/sms',{phone : tel},function (res) {
                        if(res.code==1){
                            // alert(res.msg);
                            settime();
                        }else {
                            alert(res.msg);
                        }

                    });

                }else {
                    // 手机号码已注册，中断操作
                    alert(res.msg);
                    return false;
                }

            });


        }




    }

</script>
</body>
</html>
